package com.baseweb.webadmin.service.impl;


import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.baseweb.webadmin.alipay.util.AlipaySubmit;
import com.baseweb.webadmin.bankpay.util.AcpService;
import com.baseweb.webadmin.bankpay.util.DemoBase;
import com.baseweb.webadmin.bankpay.util.LogUtil;
import com.baseweb.webadmin.bankpay.util.SDKConfig;
import com.baseweb.webadmin.core.constants.BaseState;
import com.baseweb.webadmin.core.constants.OrderPayStatus;
import com.baseweb.webadmin.core.constants.ScheduleType;
import com.baseweb.webadmin.core.constants.UserType;
import com.baseweb.webadmin.core.model.bvo.ByUserOrderDetailInfoBvo;
import com.baseweb.webadmin.core.model.bvo.ByUserOrderEvaluatvo;
import com.baseweb.webadmin.core.model.bvo.ByUserOrderInfoBvo;
import com.baseweb.webadmin.core.model.bvo.UserRoleBvo;
import com.baseweb.webadmin.core.model.dao.UserDao;
import com.baseweb.webadmin.core.model.dao.UserOrderDao;
import com.baseweb.webadmin.core.model.mapper.ByUserOrderMapper;
import com.baseweb.webadmin.core.model.mapper.UserMapper;
import com.baseweb.webadmin.core.model.mapper.UserRoleMapper;
import com.baseweb.webadmin.core.model.pojo.*;
import com.baseweb.webadmin.core.util.DateUtil;
import com.baseweb.webadmin.core.util.MD5Util;
import com.baseweb.webadmin.core.util.RandCharUtil;
import com.baseweb.webadmin.core.util.StringUtil;
import com.baseweb.webadmin.service.UserOrderService;
import com.baseweb.webadmin.service.UserService;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class UserOrderServiceImpl implements UserOrderService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserOrderDao userOrderDao;


    @Override
    public List<ByUserOrder> selectOrderListByPage(Integer userId,Integer status, Integer payStatus, Integer start, Integer offset) {
        List<Integer> userIds = new ArrayList<Integer>();
        if (userId != null && userId > 0) {
            userIds.add(userId);
        }
        return userOrderDao.selectListByPage(userIds,status, payStatus, start, offset);
    }

    @Override
    public Integer selectOrderListCount(Integer userId,Integer status, Integer payStatus) {
        List<Integer> userIds = new ArrayList<Integer>();
        if (userId != null && userId > 0) {
            userIds.add(userId);
        }
        return userOrderDao.selectListCount(userIds,status, payStatus);
    }

    @Override
    public Integer insertByUserBatchPayOrder(ByUserBatchPayOrder byUserBatchPayOrder) {
        return userOrderDao.insertByUserBatchPayOrder(byUserBatchPayOrder);
    }

    @Override
    public ByUserBatchPayOrder findByUserBatchPayOrder(Integer id) {
        return userOrderDao.findByUserBatchPayOrder(id);
    }

    @Override
    public ByUserBatchPayOrder findByUserBatchPayOrderByNum(String batchNum) {
        return userOrderDao.findByUserBatchPayOrderByNum(batchNum);
    }

    @Override
    public Integer insertByUserOrder(ByUserOrder byUserOrder) {
        return userOrderDao.insertByUserOrder(byUserOrder);
    }

    @Override
    public ByUserOrder findByUserOrder(Integer id) {
        return userOrderDao.findByUserOrder(id);
    }

    @Override
    public List<ByUserOrder> findByUserOrderList(List<Integer> ids) {
        return userOrderDao.findByUserOrderList(ids);
    }

    @Override
    public List<ByUserOrder> selectOrderListByBizUser(Integer userId, Integer bizUserId, Integer status, Integer payStatus, Integer start, Integer offset) {
        return userOrderDao.selectOrderListByBizUser(userId, bizUserId, status, payStatus, start, offset);
    }
    @Override
    public List<ByUserOrderEvaluatvo> selectOrderListByBizUserOfEvaluation(ByUserOrder order, Integer start, Integer offset) {
        return userOrderDao.selectOrderListByBizUserOfEvaluation(order, start, offset);
    }
    @Override
    public List<ByUserOrderInfoBvo> selectOrderListByPage(Integer userId,String area,Integer guserId, Integer bizUserId, Integer status, Integer payStatus,String startTime,String endTime,ByUserOrderInfoBvo user,String professionName, Integer start, Integer offset) {
        return userOrderDao.selectOrderListByPage(userId, area,guserId,bizUserId, status, payStatus,startTime,endTime,user, professionName,start, offset);
    }

    @Override
    public ByUserOrderInfoBvo sumPriceFromOrder(Integer userId, String area, Integer guserId, Integer bizUserId, Integer status, Integer payStatus, String startTime, String endTime, ByUserOrderInfoBvo user, String professionName, Integer start, Integer offset) {
        return userOrderDao.sumPriceFromOrder(userId, area,guserId,bizUserId, status, payStatus,startTime,endTime,user, professionName,start, offset);
    }

    @Override
    public Integer selectOrderListByBizUserCount(Integer userId,String area,Integer guserId,  Integer bizUserId, Integer status, Integer payStatus,String startTime,String endTime,String professionName,ByUserOrderInfoBvo user) {
        return userOrderDao.selectOrderListByBizUserCount(userId,area,guserId, bizUserId, status,payStatus,startTime,endTime,professionName,user);
    }
    @Override
    public Integer selectOrderListByBizUserCountzOfEvalution(ByUserOrder user) {
        return userOrderDao.selectOrderListByBizUserCountzOfEvalution(user);
    }
    @Override
    public List<ByUserOrder> selectAllOrderListByPage(Integer userId, Integer start, Integer offset) {
        return userOrderDao.selectAllOrderListByPage(userId, start, offset);
    }

    @Override
    public Integer selectAllOrderListCount(Integer userId) {
        return userOrderDao.selectAllOrderListCount(userId);
    }

    @Override
    public Integer insertByUserOrderDetail(ByUserOrderDetail byUserOrderDetail) {
        return userOrderDao.insertByUserOrderDetail(byUserOrderDetail);
    }

    @Override
    public ByUserOrderDetail findByUserOrderDetail(Integer id) {
        return userOrderDao.findByUserOrderDetail(id);
    }

    @Override
    public List<ByUserOrderDetail> selectOrderDetailListByPage(Integer userId, Integer orderId, Integer start, Integer offset) {
        return userOrderDao.selectOrderDetailListByPage(userId, orderId, start, offset);
    }

    @Override
    public List<ByUserOrderDetailInfoBvo> selectOrderDetailListByHtmlPage(Integer userId, Integer orderId, Integer start, Integer offset) {
        return userOrderDao.selectOrderDetailListByHtmlPage(userId, orderId, start, offset);
    }
    @Override
    public Integer selectOrderDetailListCount(Integer userId, Integer orderId) {
        return userOrderDao.selectOrderDetailListCount(userId, orderId);
    }

    @Override
    public Integer insertSchedule(ByUserBizSchedule byUserBizSchedule) {
        return userOrderDao.insertSchedule(byUserBizSchedule);
    }

    @Override
    public ByUserBizSchedule findSchedule(Integer id) {
        return userOrderDao.findSchedule(id);
    }

    @Override
    public Integer deleteSchedule(Integer id) {
        return userOrderDao.deleteSchedule(id);
    }

    @Override
    public Integer deleteSchedule(Integer type, DateTime dateTime, Integer userId) {
        return userOrderDao.deleteSchedule(type, dateTime, userId);
    }

    @Override
    public Integer deleteScheduleByOrderId(Integer orderId) {
        return userOrderDao.deleteScheduleByOrderId(orderId);
    }

    @Override
    public List<ByUserBizSchedule> selectScheduleListByPage(Integer userId, Integer status, Integer start, Integer offset) {
        return userOrderDao.selectScheduleListByPage(userId, status, start, offset);
    }

    @Override
    public Integer selectScheduleListCount(Integer userId, Integer status) {
        return userOrderDao.selectScheduleListCount(userId, status);
    }

    @Override
    public List<ByUserBizSchedule> selectScheduleRemindList(Integer userId, Integer status, DateTime startTime, DateTime endTime) {
        return userOrderDao.selectScheduleRemindList(userId, status, startTime, endTime);
    }

    @Override
    public List<ByUserBizSchedule> selectScheduleListByPage(Integer userId, Integer status, DateTime startTime, DateTime endTime, Integer start, Integer offset) {
        return userOrderDao.selectScheduleListByPage(userId, status, startTime, endTime, start, offset);
    }

//    @Override
//    public boolean isScheduled(Integer userId, Integer status, DateTime scheduleTime, Integer dinnerType) {
//        return userOrderDao.isScheduled(userId, status, scheduleTime, dinnerType);
//    }

    @Override
    public Map<String, String> getUserScheduleListView(Integer user_id, int year, int month, int day) {
        DateTime startTime = null;
        if (year > 0 && month > 0 && day > 0)  {
            startTime = new DateTime(year, month, day, 0, 0, 0);
        }

        List<ByUserBizSchedule> scheduleList = null;

        Map<String, String> map = new HashMap<String, String>();

        User user = userDao.selectUserById(user_id);

        if (user.getUserType().intValue() == UserType.TEAM_BIZ.getCode()){
            scheduleList = userOrderDao.selectScheduleListByPage(user_id, BaseState.DELETE.getCode(),startTime, 0,Integer.MAX_VALUE);

            if (scheduleList != null && scheduleList.size() > 0){
                for (ByUserBizSchedule current : scheduleList){
//                    Map map = new HashMap();
                    map.put(DateUtil.dateToString(current.getScheduleDate(), "yyyyMMdd"),"greyClass");
//                    result.add(map);
                }
            }
        }else{
            scheduleList = userOrderDao.selectScheduleListByPage(user_id,null,startTime,0,Integer.MAX_VALUE);

            if (scheduleList != null && scheduleList.size() > 0){
                Set set = new HashSet();
                for (ByUserBizSchedule current : scheduleList){
//                    Map map = new HashMap();
                    String dateStr = DateUtil.dateToString(current.getScheduleDate(), "yyyyMMdd");
                    if (current.getStatus().intValue() == BaseState.DELETE.getCode()){
                        map.put(dateStr,"greyClass");
//                        result.add(map);
                    }else{
                        if (set.contains(dateStr)){
                            map.put(dateStr,"redClass");

//                            result.add(map);
                        }else{
                            set.add(dateStr);

                            if (current.getScheduleType().intValue() == ScheduleType.LUNCH.getCode()){
                                map.put(dateStr, "lunchClass");
                            }else if(current.getScheduleType().intValue() == ScheduleType.DINNER.getCode()){
                                map.put(dateStr, "dinnerClass");
                            }
                        }

                    }
                }
            }
        }

        return  map;
    }

    @Override
    public Map<String, String> getUserScheduleListView(Integer user_id, int year, int month) {
        DateTime startTime = null;
        DateTime endTime = null;
        if (year > 0 && month > 0){
            DateTime currentDt = new DateTime();
            startTime = new DateTime(year, month, 1, 0, 0, 0);
            endTime = startTime.plusMonths(1);
        }

        List<ByUserBizSchedule> scheduleList = null;

        Map<String, String> map = new HashMap<String, String>();

        User user = userDao.selectUserById(user_id);

        if (user.getUserType().intValue() == UserType.TEAM_BIZ.getCode()){
            scheduleList = userOrderDao.selectScheduleListByPage(user_id, BaseState.DELETE.getCode(),startTime, endTime,0,Integer.MAX_VALUE);

            if (scheduleList != null && scheduleList.size() > 0){
                for (ByUserBizSchedule current : scheduleList){
//                    Map map = new HashMap();
                    map.put(DateUtil.dateToString(current.getScheduleDate(), "yyyyMMdd"),"greyClass");
//                    result.add(map);
                }
            }
        }else{
            scheduleList = userOrderDao.selectScheduleListByPage(user_id,null,startTime, endTime,0,Integer.MAX_VALUE);

            if (scheduleList != null && scheduleList.size() > 0){
                Set set = new HashSet();
                for (ByUserBizSchedule current : scheduleList){
                    String dateStr = DateUtil.dateToString(current.getScheduleDate(), "yyyyMMdd");
                    String key = dateStr + "-" + current.getScheduleType();
                    System.out.println(key + " ---- " + dateStr);
                    if (current.getStatus().intValue() != BaseState.DELETE.getCode()){
                        if (set.contains(key)){
                            map.put(key,"redClass");
                        }else{
                            set.add(key);
                            if (current.getScheduleType().intValue() == ScheduleType.LUNCH.getCode()){
                                map.put(key, "lunchClass");
                            }else if(current.getScheduleType().intValue() == ScheduleType.DINNER.getCode()){
                                map.put(key, "dinnerClass");
                            }
                        }
                    }
                }
            }
        }

        return  map;
    }

    @Override
    public Integer selectScheduleListCount(Integer userId, Integer status, DateTime startTime, DateTime endTime) {
        return userOrderDao.selectScheduleListCount(userId, status, startTime, endTime);
    }

    @Override
    public List<ByUserOrder> selectBizOrderListByPage(Integer userId, Integer status, Integer start, Integer offset) {
        List<Integer> userIds = new ArrayList<Integer>();
        userIds.add(userId);
        return userOrderDao.selectBizOrderListByPage(userIds, status, start, offset);
    }

    @Override
    public Integer selectBizOrderListCount(Integer userId, Integer status) {
        List<Integer> userIds = new ArrayList<Integer>();
        userIds.add(userId);
        return userOrderDao.selectBizOrderListCount(userIds, status);
    }

    @Override
    public List<ByUserOrder> selectBizOrderListByPage(List<Integer> userIds, Integer status, Integer start, Integer offset) {
        return userOrderDao.selectBizOrderListByPage(userIds, status, start, offset);
    }

    @Override
    public Integer selectBizOrderListCount(List<Integer> userIds, Integer status) {
        return userOrderDao.selectBizOrderListCount(userIds, status);
    }

    @Override
    public Integer countOrderDiscuss(Integer id) {
        return userOrderDao.countOrderDiscuss(id);
    }

    @Override
    public List<ByUserOrder> selectOrderByProductId(Integer id) {
        return userOrderDao.selectOrderByProductId(id);
    }

    @Override
    public boolean selectScheduleByUserId(int userId, String scheduleDate, String scheduleType) {
        int result = userOrderDao.selectScheduleByUserId(userId, scheduleDate, scheduleType);
        return result > 0 ? false : true;
    }

    @Override
    public String ordersPay(String orderId, Integer userId, Integer status,String payFor) {
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setTimeoutExpress("30m");
        model.setProductCode("QUICK_MSECURITY_PAY");


        if (orderId.indexOf(",") != -1){
            String orderIds[] = orderId.split(",");

            if (orderIds != null && orderIds.length > 0){
                //add batch order
                BigDecimal totalPrice = BigDecimal.ZERO;
                BigDecimal totalDeposit = BigDecimal.ZERO;

                List<Integer> orderIdList = new ArrayList<Integer>();
                for (int i = 0; i < orderIds.length; i++) {
                    orderIdList.add(Integer.valueOf(orderIds[i]));
                }
                List<ByUserOrder> orderList = userOrderDao.findByUserOrderList(orderIdList);

                for (ByUserOrder current : orderList){
                    totalPrice = totalPrice.add(current.getPrice());
                    totalDeposit = totalDeposit.add(current.getDeposit());
                }

                ByUserBatchPayOrder batchOrder = new ByUserBatchPayOrder();
                batchOrder.setUserId(userId);
                batchOrder.setBatchNum("bt-"+ MD5Util.Md5(DateUtil.dateToString(new DateTime())+ RandCharUtil.getRandStr(8)));
                batchOrder.setOrderIds(orderId);
                batchOrder.setPrice(totalPrice);
                batchOrder.setPriceType(status);
                batchOrder.setCreateTime(new DateTime());
                batchOrder.setUpdateTime(new DateTime());
                batchOrder.setDescn("批量订单支付");
                batchOrder.setStatus(BaseState.DELETE.getCode());  //未付款

                userOrderDao.insertByUserBatchPayOrder(batchOrder);
                model.setOutTradeNo(batchOrder.getBatchNum());
                model.setSubject("博艺网订单_"+batchOrder.getBatchNum());

                if (status.intValue() == OrderPayStatus.PAY_ALL.getCode()){
                    model.setTotalAmount(totalPrice.toString());
                }else{
                    model.setTotalAmount(totalDeposit.toString());
                }
                model.setBody(batchOrder.getDescn());
            }
        }else{
            ByUserOrder byUserOrder = userOrderDao.findByUserOrder(Integer.valueOf(orderId));
            model.setOutTradeNo(orderId);
            model.setSubject("博艺网订单_"+orderId);

            if (status.intValue() == OrderPayStatus.PAY_ALL.getCode()){
                model.setTotalAmount(byUserOrder.getPrice().toString());
                byUserOrder.setAlipaytotalfee(byUserOrder.getPrice());
            }else{
                model.setTotalAmount(byUserOrder.getDeposit().toString());
                byUserOrder.setAlipaytotalfee(byUserOrder.getDeposit());
            }
            userOrderDao.insertByUserOrder(byUserOrder);
            model.setBody(byUserOrder.getDescn());
        }
        String payParam = null;
        if(StringUtil.isNotBlank(payFor) && "bank".equals(payFor)){
            List<Card> cardList = userMapper.findAllCard(userId);
            String cardId = cardList != null && cardList.size() > 0 ? cardList.get(0).getCardnumber() : null;
            Map<String, String> reqData = ordersPayByBank(model.getOutTradeNo(),model.getTotalAmount(),cardId,"app");
            LogUtil.writeLog("打印手机生成参数："+reqData);
            String requestAppUrl = SDKConfig.getConfig().getAppRequestUrl();								 //交易请求url从配置文件读取对应属性文件acp_sdk.properties中的 acpsdk.backTransUrl
            Map<String, String> rspData = AcpService.post(reqData,requestAppUrl,DemoBase.encoding);  //发送请求报文并接受同步应答（默认连接超时时间30秒，读取返回结果超时时间30秒）;这里调用signData之后，调用submitUrl之前不能对submitFromData中的键值对做任何修改，如果修改会导致验签不通过
            LogUtil.writeLog("打印手机地址返回参数："+rspData);
            /**对应答码的处理，请根据您的业务逻辑来编写程序,以下应答码处理逻辑仅供参考------------->**/
            //应答码规范参考open.unionpay.com帮助中心 下载  产品接口规范  《平台接入接口规范-第5部分-附录》
            if(!rspData.isEmpty()){
                if(AcpService.validate(rspData, DemoBase.encoding)){
                    LogUtil.writeLog("验证签名成功");
                    String respCode = rspData.get("respCode") ;
                    if(("00").equals(respCode)){
                        //成功,获取tn号
                        payParam = rspData.get("tn");
                        //TODO
                    }else{
                        //其他应答码为失败请排查原因或做失败处理
                        //TODO
                    }
                }else{
                    LogUtil.writeErrorLog("验证签名失败");
                    //TODO 检查验证签名失败的原因
                }
            }else{
                //未返回正确的http状态
                LogUtil.writeErrorLog("未获取到返回报文或返回http状态码非200");
            }
            String reqMessage = DemoBase.genHtmlResult(reqData);
            String rspMessage = DemoBase.genHtmlResult(rspData);
            LogUtil.writeLog("打印请求HTML，此为请求报文，为联调排查问题的依据："+"请求报文:<br/>"+reqMessage+"<br/>" + "应答报文:</br>"+rspMessage+"");
            //将生成的html写到浏览器中完成自动跳转打开银联支付页面；这里调用signData之后，将html写到浏览器跳转到银联页面之前均不能对html中的表单项的名称和值进行修改，如果修改会导致验签不通过
//            response.getWriter().write(html);
        }else {
            //其他业务参数根据在线开发文档，添加参数.文档地址:https://doc.open.alipay.com/doc2/detail.htm?spm=a219a.7629140.0.0.O9yorI&treeId=62&articleId=103740&docType=1
            //如sParaTemp.put("参数名","参数值");

            //建立请求

            payParam = AlipaySubmit.aliPayClientSend(model);
        }
        return payParam;
    }

    @Override
    public Map<String, String> ordersPayByBank(String orderId, String txnAmt,String cardNo,String ... type) {

        Map<String, String> requestData = new HashMap<String, String>();
        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        String txnTime = df.format(new Date());

        /***银联全渠道系统，产品参数，除了encoding自行选择外其他不需修改***/
        requestData.put("version", DemoBase.version);   			  //版本号，全渠道默认值
        requestData.put("encoding", DemoBase.encoding); 			  //字符集编码，可以使用UTF-8,GBK两种方式
        requestData.put("signMethod", SDKConfig.getConfig().getSignMethod()); //签名方法
        requestData.put("txnType", "01");               			  //交易类型 ，01：消费
        requestData.put("txnSubType", "01");            			  //交易子类型， 01：自助消费
        requestData.put("bizType", "000201");           			  //业务类型，B2C网关支付，手机wap支付
        if(type != null && type.length > 0){
            requestData.put("channelType", "08");
        }else{
            requestData.put("channelType", "07");           			  //渠道类型，这个字段区分B2C网关支付和手机wap支付；07：PC,平板  08：手机
            //前台通知地址 （需设置为外网能访问 http https均可），支付成功后的页面 点击“返回商户”按钮的时候将异步通知报文post到该地址
            //如果想要实现过几秒中自动跳转回商户页面权限，需联系银联业务申请开通自动返回商户权限
            //异步通知参数详见open.unionpay.com帮助中心 下载  产品接口规范  网关支付产品接口规范 消费交易 商户通知
            requestData.put("frontUrl", DemoBase.frontUrl);
            // 订单超时时间。
            // 超过此时间后，除网银交易外，其他交易银联系统会拒绝受理，提示超时。 跳转银行网银交易如果超时后交易成功，会自动退款，大约5个工作日金额返还到持卡人账户。
            // 此时间建议取支付时的北京时间加15分钟。
            // 超过超时时间调查询接口应答origRespCode不是A6或者00的就可以判断为失败。
            requestData.put("payTimeout", df.format(new Date().getTime() + 15 * 60 * 1000));
        }

        /***商户接入参数***/
        requestData.put("merId", SDKConfig.getConfig().getMerId());   //商户号码，请改成自己申请的正式商户号或者open上注册得来的777测试商户号
        requestData.put("accessType", "0");             			  //接入类型，0：直连商户
        if(orderId.contains("-")){
            orderId = "batch" + orderId.split("-")[1];
        }else if(orderId.length() < 8){
            orderId += "boyi" + MD5Util.Md5(DateUtil.dateToString(new DateTime())+ RandCharUtil.getRandStr(8));
        }
        requestData.put("orderId",orderId);             //商户订单号，8-40位数字字母，不能含“-”或“_”，可以自行定制规则
        requestData.put("txnTime", txnTime);        //订单发送时间，取系统时间，格式为YYYYMMDDhhmmss，必须取当前时间，否则会报txnTime无效
        requestData.put("currencyCode", "156");         			  //交易币种（境内商户一般是156 人民币）
        requestData.put("txnAmt", (int)(Double.valueOf(StringUtil.isBlank(txnAmt) ? "0" : txnAmt) * 100) + "");     //交易金额，单位分，不要带小数点
        if(StringUtil.isNotBlank(cardNo)){
            requestData.put("accNo", cardNo);         //需锁定的卡号
        }
        //requestData.put("reqReserved", "透传字段");        		      //请求方保留域，如需使用请启用即可；透传字段（可以实现商户自定义参数的追踪）本交易的后台通知,对本交易的交易状态查询交易、对账文件中均会原样返回，商户可以按需上传，长度为1-1024个字节。出现&={}[]符号时可能导致查询接口应答报文解析失败，建议尽量只传字母数字并使用|分割，或者可以最外层做一次base64编码(base64编码之后出现的等号不会导致解析失败可以不用管)。



        //后台通知地址（需设置为【外网】能访问 http https均可），支付成功后银联会自动将异步通知报文post到商户上送的该地址，失败的交易银联不会发送后台通知
        //后台通知参数详见open.unionpay.com帮助中心 下载  产品接口规范  网关支付产品接口规范 消费交易 商户通知
        //注意:1.需设置为外网能访问，否则收不到通知    2.http https均可  3.收单后台通知后需要10秒内返回http200或302状态码
        //    4.如果银联通知服务器发送通知后10秒内未收到返回状态码或者应答码非http200，那么银联会间隔一段时间再次发送。总共发送5次，每次的间隔时间为0,1,2,4分钟。
        //    5.后台通知地址如果上送了带有？的参数，例如：http://abc/web?a=b&c=d 在后台通知处理程序验证签名之前需要编写逻辑将这些字段去掉再验签，否则将会验签失败
        requestData.put("backUrl", DemoBase.backUrl);

        //////////////////////////////////////////////////
        //
        //       报文中特殊用法请查看 PCwap网关跳转支付特殊用法.txt
        //
        //////////////////////////////////////////////////

        /**请求参数设置完毕，以下对请求参数进行签名并生成html表单，将表单写入浏览器跳转打开银联页面**/
        Map<String, String> submitFromData = AcpService.sign(requestData,DemoBase.encoding);  //报文中certId,signature的值是在signData方法中获取并自动赋值的，只要证书配置正确即可。



        return submitFromData;
    }

    @Override
    public int selectOrderUnfinished(int userId, String scheduleDate, String scheduleType) {
        scheduleType = scheduleType.equals("1") ? "午宴" : "晚宴";
        return userOrderDao.selectOrderUnfinished(userId, scheduleDate, scheduleType);
    }
}
